#!/usr/local/bin/python 
import settings
from restful_lib import Connection

class restClient:
	def __init__(self):
		self.urldata = []
		urlfile = open("url.conf","r")
		self.urldata = [line.strip().replace("\"","") for line in urlfile.readlines()]
		urlfile.close()


	def connect_server(self,url,method="get"):
		base_url = url
		try :
			conn = Connection(base_url)
		except :
			return "100000"
		try :

			res = conn.request_get("/",args={},headers={'Accept':'text/json'})
		except:
			return "100001"
		status = res["headers"]["status"]
		return status
	def test(self):
		test_result = open("test_result.txt","w")
		for v in self.urldata:
			url_temp = v.split("=",1)
			url = url_temp[1]
			url_name = url_temp[0]
			print url
			try:
				status = self.connect_server(url)
			except:
				continue
			if status == "200":
				test_result.write(url_name+'    ok\n')
			else:
				test_result.write(url_name+'    failed\n')
		test_result.close()

if __name__ == "__main__":
	rc = restClient()
	rc.test()
	#print rc.connect_server("http://192.168.11.146:8030/dlc/dns/?id=10000")

